package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.RongCloudXML;
import com.digitalchina.lxnsy.xml.UserXML;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.lzy.okhttputils.model.HttpParams;
import com.ta.utdid2.android.utils.StringUtils;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2017/9/8 11:44
 * 修改备注：
 * ================================================
 */
public class BusinessPersonnelService {

    /**
     * 发布人才需求
     *
     * @param demand      需求
     * @param content       任务内容
     * @param contactPeople 联系人
     * @param peopleNum     人数
     * @param price         价格
     * @param address       详细地址
     * @param tel           联系电话
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @param demandCode    招聘要求编码
     * @param provinceCode  省份编码
     * @param cityCode      城市编码
     * @param countyCode    区县编码
     */
    public static void editDemand(Activity activity, String demand, String content, String contactPeople, String peopleNum, String price, String address, String tel, String startTime, String endTime, String demandCode, String provinceCode, String cityCode, String countyCode, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("demand", demand);
        params.put("content", content);
        params.put("contactPeople", contactPeople);
        params.put("peopleNum", peopleNum);
        params.put("price", price);
        params.put("address", address);
        params.put("tel", tel);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("demandCode", demandCode);
        params.put("provinceCode", provinceCode);
        params.put("cityCode", cityCode);
        params.put("countyCode", countyCode);

        OkHttpUtil.post(activity, URL.URL_EDIT_DEMAND, "", params, handler, MSG.MSG_EDIT_DEMAND_SUCCESS, MSG.MSG_EDIT_DEMAND_FIELD);
    }

    /**
     * 发布人才供需
     *
     * @param content       任务内容
     * @param contactPeople 联系人
     * @param peopleNum     人数
     * @param price         价格
     * @param address       详细地址
     * @param tel           联系电话
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @param demand    招聘要求编码
     */
    public static void AddSupply(Activity activity,String type, String content, String contactPeople, String peopleNum, String price, String address, String tel, String startTime, String endTime, String demand, Handler handler) {


        try {
            final JSONObject params = new JSONObject();

            params.put("type", type);
            params.put("content", content);
            params.put("contacts", contactPeople);
            params.put("number", peopleNum);
            params.put("price", price);
            params.put("demand", demand);
            params.put("address", address);
            params.put("telephone", tel);
            params.put("startDate", startTime);
            params.put("endDate", endTime);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));

            OkHttpUtil.post(activity, URL.URL_ADD_SUPPLY, "", params, handler, MSG.MSG_EDIT_DEMAND_SUCCESS, MSG.MSG_EDIT_DEMAND_FIELD);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    /**
     * 发布人才供需
     *
     * @param content       任务内容
     * @param contactPeople 联系人
     * @param peopleNum     人数
     * @param price         价格
     * @param address       详细地址
     * @param tel           联系电话
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @param demand    招聘要求编码
     */
    public static void editSupply(Activity activity,String id,String type, String content, String contactPeople, String peopleNum, String price, String address, String tel, String startTime, String endTime, String demand, Handler handler) {


        try {
            final JSONObject params = new JSONObject();

            params.put("type", type);
            params.put("content", content);
            params.put("contacts", contactPeople);
            params.put("number", peopleNum);
            params.put("price", price);
            params.put("demand", demand);
            params.put("address", address);
            params.put("telephone", tel);
            params.put("startDate", startTime);
            params.put("endDate", endTime);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));

            OkHttpUtil.post(activity, URL.URL_EDIT_SUPPLY+id, "", params, handler, MSG.MSG_EDIT_DEMAND_SUCCESS, MSG.MSG_EDIT_DEMAND_FIELD);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取人才职称
     *
     * @param activity
     * @param handler
     */
    public static void getTalentTitles(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("productName","羊");
        OkHttpUtil.get(activity, URL.URL_GET_TALENT_TITLES, "", params, handler, MSG.MSG_GET_TALENT_TITLES_SUCCESS, MSG.MSG_GET_TALENT_TITLES_FIELD);

    }


    /**
     * 人才需求列表
     *
     * @param activity
     * @param titleCode  职称code
     * @param cityCode   城市code 主要针对杨凌示范区
     * @param countyCode 区code
     * @param lowPrice   最低价格
     * @param highPrice  最高价格
     * @param handler
     */
    public static void getDemandList(Activity activity, String page, String titleCode, String cityCode, String countyCode, String lowPrice, String highPrice, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("titleCode", titleCode);
        params.put("cityCode", cityCode);
        params.put("countyCode", countyCode);
        params.put("lowPrice", lowPrice);
        params.put("highPrice", highPrice);
        params.put("limit", "10");
        params.put("page", page);

        OkHttpUtil.post(activity, URL.URL_GET_DEMAND_LIST, "", params, handler, MSG.MSG_GET_DEMAND_LIST_SUCCESS, MSG.MSG_GET_DEMAND_LIST_FIELD);

    }

    /**
     * 人才供应列表
     *
     * @param activity
     * @param type  0:人才供应 1:人才需求
     * @param content   内容搜索
     * @param dateRange   日期范围（yyyy-MM-dd,yyyy-MM-dd）
     * @param priceStart  最低价格
     * @param priceEnd  最高价格
     * @param handler
     */
    public static void getSupplyAndDemandList(Activity activity, String page, String type, String content, String dateRange, String priceStart, String priceEnd,String createdBy,String queryDataType, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("type", type);
      /*  params.put("content", content);
        params.put("dateRange", dateRange);
        params.put("priceStart", priceStart);
        params.put("priceEnd", priceEnd);*/
        params.put("createdBy", createdBy);
        params.put("limit", "10");
        params.put("perPage", page);
        params.put("queryDataType", queryDataType);
        OkHttpUtil.get(activity, URL.URL_GET_SUPPLY_DEMAND_LIST, "", params, handler, MSG.MSG_GET_DEMAND_LIST_SUCCESS, MSG.MSG_GET_DEMAND_LIST_FIELD);

    }

    /**
     * 我发布的需求
     *
     * @param activity
     * @param page
     * @param handler
     */
    public static void getMyDemands(Activity activity, String page, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity));
        params.put("limit", "10");
        params.put("page", page);

        OkHttpUtil.post(activity, URL.URL_GET_MY_DEMANDS, "", params, handler, MSG.MSG_GET_DEMAND_LIST_SUCCESS, MSG.MSG_GET_DEMAND_LIST_FIELD);

    }

    /**
     * 我发布的供应
     *
     * @param activity
     * @param page
     * @param handler
     */
    public static void getMySupplies(Activity activity, String page, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", UserXML.getUserId(activity));
        params.put("limit", "10");
        params.put("page", page);

        OkHttpUtil.post(activity, URL.URL_GET_MY_SUPPLIES, "", params, handler, MSG.MSG_GET_DEMAND_LIST_SUCCESS, MSG.MSG_GET_DEMAND_LIST_FIELD);

    }

    /**
     * 人才服务详情 根据ID获取
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void getTalentsInfo(Activity activity, String id, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.get(activity, URL.URL_GET_TALENTS_INFO+id, "", params, handler, MSG.MSG_GET_TALENTS_INFO_SUCCESS, MSG.MSG_GET_TALENTS_INFO_FIELD);

    }
    /**
     * 删除人才需求
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void deleteTalentDemand(Activity activity, String id, Handler handler) {

        final JSONObject params = new JSONObject();

        OkHttpUtil.post(activity, URL.URL_DELETE_SUPPLY+id, "", params, handler, MSG.MSG_DEL_DEMAND_SUCCESS, MSG.MSG_DEL_DEMAND_FIELD);

    }
    /**
     * 人才浏览操作记录
     *
     */
    public static void saveFarmGangOperation(Activity activity, String eventId,  Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_SAVE_FARM_GANG_OPERATION+eventId, "", params, handler, MSG.MSG_SAVE_FARM_GANG_OPERATION_SUCCESS, MSG.MSG_SAVE_FARM_GANG_OPERATION_FIELD);

    }
    /**
     * 人才打电话操作记录
     *
     */
    public static void saveTelOperation(Activity activity, String eventId,  Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_SAVE_TEL+eventId, "", params, handler, MSG.MSG_SAVE_FARM_GANG_OPERATION_SUCCESS, MSG.MSG_SAVE_FARM_GANG_OPERATION_FIELD);
    }


    /**
     * 良种羊
     *
     * @param activity
     * @param type  0:供应 1:需求
     * @param content   内容搜索
     * @param dateRange   日期范围（yyyy-MM-dd,yyyy-MM-dd）
     * @param priceStart  最低价格
     * @param priceEnd  最高价格
     * @param handler
     */
    public static void getSheepList(Activity activity, String page, String type, String content, String dateRange, String priceStart, String priceEnd,String createdBy,String queryDataType, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("type", type);
        params.put("perpage", "10");
        params.put("page", page);
        params.put("createdBy", createdBy);
        params.put("queryDataType", queryDataType);
        OkHttpUtil.get(activity, URL.URL_GET_SLEEP_LIST, "", params, handler, MSG.MSG_GET_DEMAND_LIST_SUCCESS, MSG.MSG_GET_DEMAND_LIST_FIELD);

    }

    /**
     * 品种
     *
     * @param activity
     * @param handler
     */
    public static void getVariety(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("pCode","MILKGOATVARIETY");
        OkHttpUtil.get(activity, URL.URL_SHARE_FARM_TYPE, "", params, handler, MSG.MSG_GET_ACTIVITY_TYPE_SUCCESS, MSG.MSG_GET_ACTIVITY_TYPE_FIELD);

    }

    /**
     * 发布良品羊
     *
     * @param content       任务内容
     * @param contactPeople 联系人
     * @param peopleNum     人数
     * @param price         价格
     * @param address       详细地址
     * @param tel           联系电话
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @param variety
     */
    public static void addSleep(Activity activity,String type, String content, String contactPeople, String peopleNum, String price, String address, String tel, String startTime, String endTime, String variety,String grade, String imgs,Handler handler) {

        try {
            final JSONObject params = new JSONObject();

            params.put("type", type);
            params.put("content", content);
            params.put("contacts", contactPeople);
            params.put("breedName", variety);
            params.put("grade", grade);
            params.put("number", peopleNum);
            params.put("price", price);
            params.put("address", address);
            params.put("telephone", tel);
            params.put("startDate", startTime);
            params.put("endDate", endTime);
            params.put("uploadImgs", imgs);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));

            OkHttpUtil.post(activity, URL.URL_ADD_SLEEP, "", params, handler, MSG.MSG_LOGIN_SUCCESS, MSG.MSG_LOGIN_FAILED);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    /**
     * 发布良品羊
     *
     * @param content       任务内容
     * @param contactPeople 联系人
     * @param peopleNum     人数
     * @param price         价格
     * @param address       详细地址
     * @param tel           联系电话
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @param variety
     */
    public static void editSleep(Activity activity,String type,String id, String content, String contactPeople, String peopleNum, String price, String address, String tel, String startTime, String endTime, String variety,String grade, String imgs,Handler handler) {

        try {
            final JSONObject params = new JSONObject();

            params.put("type", type);
            params.put("content", content);
            params.put("contacts", contactPeople);
            params.put("breedName", variety);
            params.put("grade", grade);
            params.put("number", peopleNum);
            params.put("price", price);
            params.put("address", address);
            params.put("telephone", tel);
            params.put("startDate", startTime);
            params.put("endDate", endTime);
            params.put("uploadImgs", imgs);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));

            OkHttpUtil.post(activity, URL.URL_EDIT_SLEEP+id, "", params, handler, MSG.MSG_LOGIN_SUCCESS, MSG.MSG_LOGIN_FAILED);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    /**
     * 良种羊服务详情 根据ID获取
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void getSheepInfo(Activity activity, String id, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.get(activity, URL.URL_GET_SHEEP_INFO+id, "", params, handler, MSG.MSG_GET_TALENTS_INFO_SUCCESS, MSG.MSG_GET_TALENTS_INFO_FIELD);

    }

    /**
     * 删除良种羊
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void deleteSheep(Activity activity, String id, Handler handler) {

        final JSONObject params = new JSONObject();

        OkHttpUtil.post(activity, URL.URL_DELETE_SHEEP+id, "", params, handler, MSG.MSG_DEL_DEMAND_SUCCESS, MSG.MSG_DEL_DEMAND_FIELD);

    }

    /**
     * 良种羊浏览操作记录
     *
     */
    public static void saveSheepOperation(Activity activity, String eventId,  Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_SAVE_SHEEP_OPERATION+eventId, "", params, handler, MSG.MSG_SAVE_FARM_GANG_OPERATION_SUCCESS, MSG.MSG_SAVE_FARM_GANG_OPERATION_FIELD);

    }
    /**
     * 良种羊打电话操作记录
     *
     */
    public static void saveSheepTelOperation(Activity activity, String eventId,  Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_SAVE_SHEEP_TEL+eventId, "", params, handler, MSG.MSG_SAVE_FARM_GANG_OPERATION_SUCCESS, MSG.MSG_SAVE_FARM_GANG_OPERATION_FIELD);
    }

}
